<?php


namespace app\admin\controller;
use think\Request;
use think\Session;
class Base extends \think\Controller{

 
    public function __construct() {
        parent::__construct();
      
        $mg_id = Session::get('mg_id');
        $mg_name = Session::get('mg_name');   
        $str = Request::instance()->controller().'-'.Request::instance()->action();
        $auth_path = ['Manager-login','Manager-logout'];
        if(empty($mg_name) && !in_array($str, $auth_path)){
              $this->redirect('Manager/login');
          }
        $info = db('manager')->where('mg_status',1)->find($mg_id);
        $role_id = $info['mg_role_id'];
        $data = db('role')->find($role_id);
        $arr = $data['role_auth_ca'];
        $arr = explode(',', $arr);
//        dump($str);
//        dump($arr);exit;
        $public = ['Manager-login','Manager-logout','Index-index','Index-welcome'];
        if(!in_array($str, $arr) && $mg_id !== 1 && !in_array($str, $public)){
            $this->error('没有权限访问!','index/welcome');
        }
        
    }
    
    


}
